<?php

namespace App\Http\Controllers\Web;

use App\Models\WalletLogs;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CostController extends Controller
{


    /**
     * 资金明细
     */
    public function wallet(Request $request)
    {
        if ($request->ajax()) {
        	
        	$sortName = $request->post("sortName");    //排序列名
			$sortOrder = $request->post("sortOrder");   //排序（desc，asc）
			$pageNumber = $request->post("pageNumber");  //当前页码
			$pageSize = $request->post("pageSize");   //一页显示的条数
			$start = ($pageNumber-1)*$pageSize;   //开始位置
			$search = $request->post("search",'');  //搜索条件
			
			$total = WalletLogs::where("uid","=",auth('web')->user()->id)
					->where(function ($query) {
		                $query->where("type","=","0")
		                ->orwhere("type","=","9")
		                ->orwhere("type","=","5");
		            });
			$rows =  WalletLogs::where("uid","=",auth('web')->user()->id)
					->where(function ($query) {
		                $query->where("type","=","0")
		                ->orwhere("type","=","9")
		                ->orwhere("type","=","5");
		            });
			
	        if(trim($search)){
	        	$total->where(function ($query) use ($search) {
                    $query->where('remarks', 'LIKE', '%' . $search . '%');
                });
	        	$rows->where(function ($query) use ($search) {
                    $query->where('remarks', 'LIKE', '%' . $search . '%');
                });
	        }
	        
	        $data['total'] = $total->count();
	        $data['rows'] = $rows->skip($start)->take($pageSize)
					        ->orderBy($sortName, $sortOrder)
					        ->get();
	        
	        return response()->json($data);
        }
        return view('web.cost.wallet');
    }


    /**
     * 赠送金明细
     */
    public function donation(Request $request)
    {
        if ($request->ajax()) {
            
        	$sortName = $request->post("sortName");    //排序列名
			$sortOrder = $request->post("sortOrder");   //排序（desc，asc）
			$pageNumber = $request->post("pageNumber");  //当前页码
			$pageSize = $request->post("pageSize");   //一页显示的条数
			$start = ($pageNumber-1)*$pageSize;   //开始位置
			$search = $request->post("search",'');  //搜索条件
			
			$total = WalletLogs::where("uid","=",auth('web')->user()->id)
					->where("type","!=","0")
		            ->where("type","!=","9")
		            ->where("type","!=","5");
			$rows =  WalletLogs::where("uid","=",auth('web')->user()->id)
					->where("type","!=","0")
		            ->where("type","!=","9")
		            ->where("type","!=","5");
			
	        if(trim($search)){
	        	$total->where(function ($query) use ($search) {
                    $query->where('remarks', 'LIKE', '%' . $search . '%');
                });
	        	$rows->where(function ($query) use ($search) {
                    $query->where('remarks', 'LIKE', '%' . $search . '%');
                });
	        }
	        
	        $data['total'] = $total->count();
	        $data['rows'] = $rows->skip($start)->take($pageSize)
					        ->orderBy($sortName, $sortOrder)
					        ->get();
	        
	        return response()->json($data);
        }
        return view('web.cost.donation');
    }

}
